package com.newvpn.fastbest.zenith.activity;


import static com.newvpn.fastbest.zenith.presenter.MainActivityPresenter.REQUEST_PERSSION_VPN_1;
import static com.newvpn.fastbest.zenith.presenter.MainActivityPresenter.REQUEST_PERSSION_VPN_2;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.fragment.app.FragmentManager;

import com.best.smart.center.CenterLog;
import com.newvpn.fastbest.zenith.BuildConfig;
import com.newvpn.fastbest.zenith.R;
import com.newvpn.fastbest.zenith.dialog.NetErrorDialog;
import com.newvpn.fastbest.zenith.dialog.RateDialog;
import com.newvpn.fastbest.zenith.dialog.TestNetDialog;
import com.newvpn.fastbest.zenith.presenter.AdPresenter;
import com.newvpn.fastbest.zenith.presenter.VPNPresenter;
import com.newvpn.fastbest.zenith.utils.AdSwith;
import com.newvpn.fastbest.zenith.utils.VLog;


public class CommonSettingActivity extends BaseActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.v_activity_setting);
        initViews();
    }

    private static final int CLICK_COUNT_THRESHOLD = 5;
    private int clickCount = 0;
    private long lastClickTime = 0;


    private void initViews() {
        findViewById(R.id.ivBack).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        TextView tvVersion = findViewById(R.id.tvVersion);
        tvVersion.setText("V "+BuildConfig.VERSION_NAME);
        findViewById(R.id.tvSetting).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                clickCount++;

                // 获取当前点击时间
                long currentClickTime = System.currentTimeMillis();

                // 检查是否在1秒内连续点击了5次
                if (clickCount >= CLICK_COUNT_THRESHOLD && (currentClickTime - lastClickTime) < 1000) {
                    // 触发事件
                    CenterLog.openLogActivity(CommonSettingActivity.this);
                    // 重置点击次数和时间
                    clickCount = 0;
                    lastClickTime = 0;
                } else if (clickCount < CLICK_COUNT_THRESHOLD && (currentClickTime - lastClickTime) >= 1000) {
                    // 如果点击间隔超过1秒，重置点击次数
                    clickCount = 1;
                }

                // 更新最后点击时间
                lastClickTime = currentClickTime;
            }
        });

    }

    public void openApp(View view) {
        Intent intent = new Intent(this, AppsListActivity.class);
        startActivityForResult(intent,1);
        VLog.event("Application_VPN_Click");

    }

    public void openRateus(View view) {
        RateDialog dialog = RateDialog.newInstance();
        dialog.setCancelable(true);
        FragmentManager fragmentManager = getSupportFragmentManager();
        dialog.show(fragmentManager, "");
        VLog.event("Rate_Us");
    }

    public void openInfo(View view) {
        Intent intent = new Intent(this, InfoActivity.class);
        startActivity(intent);
        VLog.event("Privacy_Policy");
    }

    public void openTestNet(View view) {
        TestNetDialog dialog = TestNetDialog.newInstance();
        dialog.setCancelable(false);
        FragmentManager fragmentManager = getSupportFragmentManager();
        dialog.show(fragmentManager, "");
        VLog.event("Test_Click");
    }

    public void openComit(View view) {
        Intent intent = new Intent(this, FeedbackActivity.class);
        startActivity(intent);
        VLog.event("Feedback_Click");
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 1) {
            if (AdSwith.hideAdAfterSetApp){
                return;
            }
            AdPresenter.INSTANCE.loadAD(this,"Interstitial_Application_Back_Home",
                    null,System.currentTimeMillis(),3 * 1000);
        }
    }


}
